//
//  TableViewController.m
//  Advertisement
//
//  Created by mac on 16/3/24.
//  Copyright © 2016年 Appcoda. All rights reserved.
//

#import "TableViewController.h"

#import "netWork.h"
#import "MAin.h"
@interface TableViewController ()

@end

@implementation TableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _tableView = [[UITableView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    self.title = self.myTitle;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.rowHeight = 80;
    [self.view addSubview:_tableView];
    [self JsonAnalyze];
}
- (void)JsonAnalyze{
    //传值
    _userdefaults1 = [NSUserDefaults standardUserDefaults];
    NSString *idString =[NSString stringWithFormat:@"%@", [_userdefaults1 valueForKey:@"row1"]];
//    NSLog(@"+++++++%@",idString);
    _titleTwoArray = [[NSMutableArray alloc]init];
    [netWork scroll:^(NSArray *arr) {
        [_titleTwoArray setArray:arr];
        [_tableView reloadData];
    } type:[NSString stringWithFormat:@"app_loadType?id=%@",idString]];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _titleTwoArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//    static NSString *UIimage = @"Identifer";
//    //为节省内存，获取之前的存在的tableViewCell
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:UIimage];
    UITableViewCell*cell=[tableView cellForRowAtIndexPath:indexPath];

    MAin *main = [_titleTwoArray objectAtIndex:indexPath.row];

    if( cell == nil ){
        //创建UITableViewCell对象，设置行的样式和别名
//        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:UIimage];
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.selectionStyle=UITableViewCellEditingStyleNone;
        cell.textLabel.text = main.name;
        cell.textLabel.font = [UIFont systemFontOfSize:18];
        cell.textLabel.textColor =[UIColor blueColor];
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    TableViewThreeController *tableThreeView = [[TableViewThreeController alloc]init];
    _userdefaults2 = [NSUserDefaults standardUserDefaults];
    MAin * main = [_titleTwoArray objectAtIndex:indexPath.row];
    NSString * intNumber = [NSString stringWithFormat:@"%@",main.ID];
    NSLog(@"22222222-----%@",intNumber);
    [_userdefaults2 setValue:intNumber forKey:@"row2"];
    
    tableThreeView.hidesBottomBarWhenPushed = YES;
    tableThreeView.myTitle = main.name;
    [self.navigationController pushViewController:tableThreeView animated:NO];


}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
